package com.example.jucdemo.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.jucdemo.entity.TUser;
import com.example.jucdemo.mapper.UserMapper;
import org.springframework.stereotype.Service;

@Service
public class UserService extends ServiceImpl<UserMapper, TUser> implements IService<TUser> {
    // @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    // public void updateUser(PlatformTransactionManager transactionManager
    //         , List<TransactionStatus> transactionStatuses
    //         , List<TUser> users) {
    //     // 使用这种方式将事务状态都放在同一个事务里面
    //     DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    //     def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别，开启新事务，这样会比较安全些。
    //     TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态
    //     transactionStatuses.add(status);
    //
    //     // 批量更新数据
    //     updateBatchById(users);
    //
    //     String s = RandomUtils.randomDecisionWithWeight(new String[]{"ok", "bbq"}, new int[]{10, 1});
    //     if (s.equals("bbq")) {
    //         int a = 1/0;
    //     }
    //
    //
    //     System.out.println("子线程：" + Thread.currentThread().getName());
    // }
}
